﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core.DS
{
    public static partial class problem
    {
        public static dynamic deleteDSProblem(int eid, int pid)
        {
            var sql = new Sql.SqlDataContext();
            var p = sql.DSProblem.FirstOrDefault(row => row.eid == eid && row.pid == pid);
            if (p == null) return new
            {
                success = false,
                msg = "题目不存在"
            };

            // Delete Status
            var sts = sql.DSStatus.Where(row => row.eid==eid && row.pid == pid);
            sql.DSStatus.DeleteAllOnSubmit(sts);

            // Delete PS
            var ps = sql.DSProblemStatistics.FirstOrDefault(row => row.eid == eid && row.pid == pid);
            if (ps != null) sql.DSProblemStatistics.DeleteOnSubmit(ps);

            // Delete Solve
            sql.DSSolve.DeleteAllOnSubmit(sql.DSSolve.Where(row => row.eid == eid && row.pid == pid));

            // Delete Problem
            sql.DSProblem.DeleteOnSubmit(p);
            sql.SubmitChanges();
            return new
            {
                success = true
            };
        }

        internal static void deleteDSProblemStatistics(Sql.DSProblemStatistics ps, int status)
        {
            if (status >= 3) --ps.submit;
            switch (status)
            {
                case 3:
                    --ps.accept;
                    break;
            }
        }
    }
}
